#include "widget.h"
#include "ui_widget.h"

#include <QThread>
#include <QDebug>

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);

    // 创建子线程
    this->myThread = new MyThread;

    // 连接信号和槽
    connect(this->myThread, SIGNAL(sendNum(int)), this, SLOT(receiveNum(int)));
}

void Widget::receiveNum(int n)
{
    qDebug() << n;
//    QThread::sleep(1);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_pushButton_clicked()
{
    // 调用 start 方法来启动子线程
    this->myThread->start();
}
